/**
 * Funkcje do kalendarza z rozkladem zajec
 * 
 */


function calendar() { 
	var _title;
	var _start; 
	var _end; 
	var _allDay; 
	var task = $("#task"); 
	var semester = $("#semester");
	var subject = $("#subject");
	var numberHour = $("#numberHour");
	var numberWeek = $("#numberWeek");
	var dimensionWeek = $("#dimensionWeek");
	var typeCourse = $("#typeCourse");
	var typeCredit = $("#typeCredit");
	var user = $("#user");
	var speciality = $("#speciality");
	var year = $("#year");
	var dimensionSemester = $("#dimensionSemester");
	var hourYear = $("#hourYear");
	var hourSemester = $("#hourSemester");

	$("#acceptOrder").click(function(){ 
	var validator = $("#form").validationEngine('validate');
		      if(validator){
			  $.ajax({
			      url: "kalendarz.php",
			      type: "POST",
			      data: "task=task",    // tu paramtery dodać
			      error: function() {alert('eerrrr');},
			      success: function() {

						calendar.fullCalendar('renderEvent',
						{
							title: task.val(),
							start: _start,
							end: _end,
							allDay: _allDay,
							url: 'http://google.com/'
							
						},
						true 

					);
					
				    
					$( "#order-form").dialog( "close" );
					setTimeout('document.getElementById(\'form\').reset()');
					

				}

			 });
		    
		    
		    }
		    return false; 
	}); 

	//$("#zendForm").validationEngine({promptPosition : "centerRight",scroll : true}); 
	$( "#dialog:ui-dialog" ).dialog( "destroy"); 
	$( "#order-form" ).dialog({ 
	      autoOpen: false, 
	      height: 600, 
	      width: 380, 
	      modal: true, 
	      buttons: { 

	      }, 
	      close: function() { 
	      } 


	}); 
	$("#cancelOrder").click(function() { 
	      $("#order-form").dialog( "close" ); 

	}); 

	
	var calendar = $('#calendar').fullCalendar({ 
	      header: { 
		    left: 'prev,next today', 
		    center: 'title', 
		    right: 'month,agendaWeek,agendaDay' 
	      }, 
	      selectable: true, 
	      selectHelper: true, 
	      select: function(start, end, allDay) { 
		    //console.log("A" + start.toString()); 
		    $( "#order-form" ).dialog( "open" ); 

		    _start = start; 
		    _end = end; 
		    _allDay = allDay; 
		    calendar.fullCalendar('unselect'); 
		}, 
		editable: true, 
		timeFormat: 'H(:mm)', 
		axisFormat: 'H(:mm)', 
		//defaultView : 'agendaWeek', 
		firstDay: 1,
		dayclick: formAddSchedule()
		
	  }); 
}